<template>
	<view class="helpCenter" :data-theme="theme" :class="theme" :style="globalColor.style">
		<HeadCustom :title="title" :isAppBtn="!isApp" :isHome="!isApp"></HeadCustom>
		<view style="padding-bottom: 6rpx;">
			<view class="help_box fboxRow Ycenter Xbetween" v-for="(item, index) in questionList" :key="index" @tap="viewHelp(item, index)">
				<view class="">
					<view class="help_name font32 font-ell1">{{ index + 1 }}.{{ item.questionTitle }}</view>
					<text class="time_txt font28">{{ item.gmtCreate }}</text>
				</view>
				<text class="bwfont bw-arrow-right img_right"></text>
			</view>
			<u-loadmore fontSize="24rpx" :status="listConfig.loading" />
		</view>
	</view>
</template>

<script>
import { questionAll } from '@/api/h5.js';
import { utf8to16, base64decode } from '@/static/js/Base64.js';
import { getRequest } from '@/static/js/common.js';
export default {
	data() {
		return {
			globalColor: getApp().globalData.globalColor,
			theme: getApp().globalData.appTheme,
			page: {
				size: 20,
				total: 0,
				current: 1
			},
			listConfig: {
				loading: ''
			},
			questionList: [],
			isApp: 0,
			title: ''
		};
	},
	onReachBottom() {
		if (this.page.size * this.page.current <= this.page.total) {
			this.page.size += 10;
			this.listConfig.loading = 'loadmore';
			this.getQuestionAll();
		} else {
			this.listConfig.loading = 'nomore';
		}
	},
	onPullDownRefresh() {
		this.page.size = 20;
		this.getQuestionAll();
		setTimeout(() => {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	methods: {
		// 查看帮助详情
		viewHelp(data, index) {
			const obj = JSON.parse(JSON.stringify(data))
			this.$set(obj, 'index', index);
			uni.setStorage({
				key: 'questions',
				data: obj,
				success: function() {
					console.log('success');
				}
			});
			this.$pageTo('/helpDetail');
		},
		// 获取数据
		getQuestionAll() {
			this.listConfig.loading = 'loading';
			questionAll({ ...this.page }).then(res => {
				if (res.data) {
					this.questionList = res.data.list;
					this.page.total = res.data.total;
					this.listConfig.loading = 'nomore';
				}
			});
		}
	},
	onLoad(option) {
		if (option && option.benwu) {
			let benwu = utf8to16(base64decode(option.benwu));
			const token = {
				access_token: getRequest(benwu, 'token'),
				// companyId: getRequest(benwu, 'companyId'),
				statusBarHeight: getRequest(benwu, 'statusBarHeight'),
				// authStatus: getRequest(benwu, 'authStatus')
			};
			getApp().globalData.statusBarHeight = token.statusBarHeight;
			// getApp().globalData.companyId = token.companyId;
			uni.setStorageSync('bw_params', JSON.stringify(token));
		}
		if (option && option.isApp) {
			getApp().globalData.isApp = option.isApp;
			this.isApp = option.isApp;
			const { bw_link } = getApp().getBWData(['bw_link']);
			bw_link.isApp = option.isApp;
			uni.setStorageSync('bw_link', JSON.stringify(bw_link));
			this.title = '帮助中心';
		} else {
			uni.setNavigationBarTitle({
				title: `帮助中心`
			});
		}
		this.getQuestionAll();
	}
};
</script>

<style lang="scss" scoped>
.helpCenter {
	min-height: 100vh;
	background-color: var(--viewBgColor);
	.help_box {
		padding: 28rpx 0;
		margin: 0 40rpx;
		border-bottom: 1px solid var(--viewDivisionColor);
		.help_name {
			margin-bottom: 28rpx;
			font-weight: 400;
			font-weight: bold;
			color: var(--contentFontDarkColor);
		}
		.time_txt {
			color: #9E9E9E;
		}
		.img_right {
			font-size: 24rpx;
			color: var(--contentFontFourColor);
		}
	}
}
</style>
